package com.leonzhangxf.ioc.container.extension;

import com.leonzhangxf.ioc.bean.HelloWorldService;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;

/**
 * The demo of use container extension point.
 *
 * @author leonzhangxf
 */
@Configuration
@ComponentScan({"com.leonzhangxf.ioc.bean", "com.leonzhangxf.ioc.container.extension"})
public class ApplicationContextForExtensionStarter {

    public static void main(String[] args) {
        AnnotationConfigApplicationContext applicationContext =
            new AnnotationConfigApplicationContext(ApplicationContextForExtensionStarter.class);

        // FactoryBean use demo.
        System.out.println("----------------------------------------------------------------");
        Object helloWorldObject = applicationContext.getBean("helloWorldObject");
        System.out.println(String.format("The hello object %s.", helloWorldObject));

        Object helloWorldObject1 = applicationContext.getBean("helloWorldObject");
        System.out.println(String.format("The hello object singleton ? %s.", helloWorldObject1 == helloWorldObject));

        Object helloWorldObjectFactory = applicationContext.getBean("&helloWorldObject");
        System.out.println(String.format("The hello object factory %s.", helloWorldObjectFactory));

        // Test the hello world bean post-processor logic.
        System.out.println("----------------------------------------------------------------");
        HelloWorldService helloWorldService = applicationContext.getBean(HelloWorldService.class);
        helloWorldService.helloWorld();
    }
}
